// components/Factory/FactoryType.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    types: Array
  },

  /**
   * 组件的初始数据
   */
  data: {
    types:[]
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onTap: function(e) {
      const id = e.currentTarget.dataset.id;
      this.triggerEvent('typetap', {id: id});
    },
    dataPage: function (data) {
      const pageSize = 6;
      const remain = parseInt(data.length / pageSize);
      const model = data.length % pageSize;
      const pages = model > 0 ? remain + 1 : remain;
      let result = [];
      for (let i = 0; i < pages; i++) {
        let list = [];
        if (model === 0) {
          for (let j = i * pageSize; j < (i + 1) * pageSize; j++) {
            list.push(data[j]);
          }
        } else {
          if (i < pages - 1) {
            for (let k = i * pageSize; k < (i + 1) * pageSize; k++) {
              list.push(data[k]);
            }
          } else {
            for (let l = i * pageSize; l < data.length; l++) {
              list.push(data[l]);
            }
          }
        }
        result.push(list);
      }
      return result;
    },
  },
  ready:function(){
    const types = this.dataPage(this.data.types);
    this.setData({types: types});
  },
  
})
